package com.guigu.qingcheng.service_user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.guigu.qingcheng.pojo.user.UserOrder;
import com.guigu.qingcheng.service_user.mapper.UserOrderMapper;
import com.guigu.qingcheng.service_user.service.UserOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
@Service
public class UserOrderServiceImpl extends ServiceImpl<UserOrderMapper, UserOrder> implements UserOrderService {

    @Autowired
    private UserOrderService userOrderService;

    @Autowired
    private UserOrderMapper userOrderMapper;

    @Override
    public Page<UserOrder> selectUserOrder(Map<String, Object> searchMap, Integer page, Integer size) {
       Page<UserOrder> pageUserOrder = new Page<>(page,size);
       QueryWrapper<UserOrder> queryWrapper = queryWrapper(searchMap);
        IPage<UserOrder> userOrderIPage = this.userOrderService.page(pageUserOrder, queryWrapper);
        return pageUserOrder;
    }

    @Override
    public List<UserOrder> selectUserOrder1(Map<String,Object> searchMap) {
        QueryWrapper<UserOrder> queryWrapper = queryWrapper(searchMap);
        return userOrderMapper.selectUserOrder(queryWrapper);
    }


    /**
     * 高级组合查询封装对象
     * @param searchMap
     * @return
     */
    public QueryWrapper<UserOrder> queryWrapper(Map<String, Object> searchMap){
        QueryWrapper<UserOrder> wrapper = new QueryWrapper<UserOrder>();
        if(searchMap!=null){
            if(searchMap.get("username") != null && !"".equals(searchMap.get("username")))
                wrapper.like("username", "%" + searchMap.get("username") + "%");
            if(searchMap.get("nickName") != null && !"".equals(searchMap.get("nickName")))
                wrapper.like("nickName", "%" + searchMap.get("nickName") + "%");
            if(searchMap.get("status") != null && !"".equals(searchMap.get("status")))
                wrapper.eq("status",searchMap.get("status"));
            if(searchMap.get("userLevel") != null && !"".equals(searchMap.get("userLevel")))
                wrapper.eq("userLevel",searchMap.get("userLevel"));
            if(searchMap.get("created1") != null && !"".equals(searchMap.get("created1")))
                wrapper.ge("created1",searchMap.get("created1"));
            if(searchMap.get("created2") != null && !"".equals(searchMap.get("created2")))
                wrapper.le("created2",searchMap.get("created2"));
        }
        return wrapper;
    }


}
